const { execQueryUrl, contextPath } = require("./utils");
const path = require("path");

function pitcher(content) {
  return content;
}

pitcher.pitch = function () {
  const param = execQueryUrl(this.resourceQuery);
  const loaders = this.loaders.filter((l) => l.path != __filename);
  if (param.get("type") == "style") {
    const cssLoaderIndex = loaders.findIndex((l) => /css\-loader/.test(l.path));
    loaders.splice(cssLoaderIndex + 1, 0, {
      path: path.resolve(__dirname, "./vue-style-loader.js"),
    });
  }
  const loaderpath = loaders
    .map((l) => contextPath(this, l.path) + "!")
    .join("");
  const resourcePath =
    contextPath(this, this.resourcePath) + this.resourceQuery;
  return `export { default } from '!!${loaderpath}${resourcePath}'`;
};

module.exports = pitcher;
